package com.colaps.gifts;

import java.util.ArrayList;
import java.util.List;

import com.colaps.gifts.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;


public class Gifts extends Activity{
	
	public static final int ADD_REGALO = 1;
	
	private ListView lst;
    private List<GiftInfo> giftstock;

    @Override
	public void onCreate (Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.regalos);
		
	}
	
	@Override
	public void onBackPressed() {
       	finish();
    }
	
	public void pulsarMiRegalo(View view){
		Intent intentMiRegalo = new Intent(this, Gift.class);
		startActivityForResult(intentMiRegalo, ADD_REGALO);		
	}
	
	@Override
	public void onStart(){
		super.onStart();
		
	}
	
	@Override
	public void onResume(){
		super.onResume();
	}
	
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data){		
		this.lst = (ListView) findViewById(R.id.listaregalos);
		GiftListAdapter giflist = (GiftListAdapter)lst.getAdapter();
		
		switch (requestCode) {		
			case ADD_REGALO:
				if (giflist == null){															
					ArrayList<String> params = data.getStringArrayListExtra(Gift.EXTRA_GIFT);
					GiftInfo regalo = new GiftInfo();
						regalo.setName(params.get(0));
						regalo.setMarca(params.get(1));
						regalo.setModelo(params.get(2));
						regalo.setTienda(params.get(3));
						regalo.setUrl(params.get(4));				
					this.giftstock = new ArrayList<GiftInfo>();
					this.giftstock.add(regalo);					
					this.lst.setAdapter(new GiftListAdapter(Gifts.this,giftstock));
				}else{
					ArrayList<String> params = data.getStringArrayListExtra(Gift.EXTRA_GIFT);
					GiftInfo regalo = new GiftInfo();
						regalo.setName(params.get(0));
						regalo.setMarca(params.get(1));
						regalo.setModelo(params.get(2));
						regalo.setTienda(params.get(3));
						regalo.setUrl(params.get(4));				
					giflist.add(regalo);
					this.lst.setAdapter(giflist);
				}
		}
	}
}
